Sensor Fusion for Kinetis MCUs (ISSDK/KSDK version)
fusion.h
Go to the documentation of this file.
1 // Copyright (c) 2014, 2015, 2016, NXP Semiconductors N.V.,
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met:
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above copyright
9 // notice, this list of conditions and the following disclaimer in the
10 // documentation and/or other materials provided with the distribution.
11 // * Neither the name of NXP Semiconductors N.V. nor the
12 // names of its contributors may be used to endorse or promote products
13 // derived from this software without specific prior written permission.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 // DISCLAIMED. IN NO EVENT SHALL NXP SEMICONDUCTORS N.V. BE LIABLE FOR ANY
19 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 
26 /*! \file fusion.h
27  \brief Lower level sensor fusion interface
28 
29  This file can be used to "tune" the performance of specific algorithms
30  within the sensor fusion library. It also defines the lower level function
31  definitions for specific algorithms. Normally, the higher level hooks
32  in sensor_fusion.h will be used, and those shown here will be left alone.
33 */
34 
35 #ifndef FUSION_H
36 #define FUSION_H
37 
38 #include "sensor_fusion.h"
39 
40 /// @name COMPUTE_1DOF_P_BASIC constants
41 ///@{
42 #define FLPFSECS_1DOF_P_BASIC 1.5F ///< pressure low pass filter time constant (s)
43 ///@}
44 
45 /// @name COMPUTE_3DOF_G_BASIC constants
46 ///@{
47 #define FLPFSECS_3DOF_G_BASIC 1.0F ///< tilt orientation low pass filter time constant (s)
48 ///@}
49 
50 /// @name COMPUTE_3DOF_B_BASIC constants
51 ///@{
52 #define FLPFSECS_3DOF_B_BASIC 7.0F ///< 2D eCompass orientation low pass filter time constant (s)
53 ///@}
54 
55 /// @name COMPUTE_6DOF_GB_BASIC constants
56 ///@{
57 #define FLPFSECS_6DOF_GB_BASIC 7.0F /// <3D eCompass orientation low pass filter time constant (s)
58 ///@}
59 
60 /// @name COMPUTE_6DOF_GY_KALMAN constants
61 ///@{
62 #define FQVY_6DOF_GY_KALMAN 2E2 ///< gyro sensor noise variance units (deg/s)^2
63 #define FQVG_6DOF_GY_KALMAN 1.2E-3 ///< accelerometer sensor noise variance units g^2
64 #define FQWB_6DOF_GY_KALMAN 2E-2F ///< gyro offset random walk units (deg/s)^2
65 #define FMIN_6DOF_GY_BPL -7.0F ///< minimum permissible power on gyro offsets (deg/s)
66 #define FMAX_6DOF_GY_BPL 7.0F ///< maximum permissible power on gyro offsets (deg/s)
67 ///@}
68 
69 /// @name COMPUTE_9DOF_GBY_KALMAN constants
70 ///@{
71 /// gyro sensor noise covariance units deg^2
72 /// increasing this parameter improves convergence to the geomagnetic field
73 #define FQVY_9DOF_GBY_KALMAN 2E2 ///< gyro sensor noise variance units (deg/s)^2
74 #define FQVG_9DOF_GBY_KALMAN 1.2E-3 ///< accelerometer sensor noise variance units g^2 defining minimum deviation from 1g sphere
75 #define FQVB_9DOF_GBY_KALMAN 5E0 ///< magnetometer sensor noise variance units uT^2 defining minimum deviation from geomagnetic sphere.
76 #define FQWB_9DOF_GBY_KALMAN 2E-2F ///< gyro offset random walk units (deg/s)^2
77 #define FMIN_9DOF_GBY_BPL -7.0F ///< minimum permissible power on gyro offsets (deg/s)
78 #define FMAX_9DOF_GBY_BPL 7.0F ///< maximum permissible power on gyro offsets (deg/s)
79 ///@}
80 
81 /// @name Fusion Function Prototypes
82 /// These functions comprise the core of the basic sensor fusion functions excluding
83 /// magnetic and acceleration calibration. Parameter descriptions are not included here,
84 /// as details are provided in sensor_fusion.h.
85 ///@{
87 void fFuseSensors(struct SV_1DOF_P_BASIC *pthisSV_1DOF_P_BASIC, struct SV_3DOF_G_BASIC *pthisSV_3DOF_G_BASIC,
88  struct SV_3DOF_B_BASIC *pthisSV_3DOF_B_BASIC, struct SV_3DOF_Y_BASIC *pthisSV_3DOF_Y_BASIC,
89  struct SV_6DOF_GB_BASIC *pthisSV_6DOF_GB_BASIC, struct SV_6DOF_GY_KALMAN *pthisSV_6DOF_GY_KALMAN,
90  struct SV_9DOF_GBY_KALMAN *pthisSV_9DOF_GBY_KALMAN,
91  struct AccelSensor *pthisAccel, struct MagSensor *pthisMag, struct GyroSensor *pthisGyro,
92  struct PressureSensor *pthisPressure, struct MagCalibration *pthisMagCal);
93 void fInit_1DOF_P_BASIC(struct SV_1DOF_P_BASIC *pthisSV, struct PressureSensor *pthisPressure, float flpftimesecs);
94 void fInit_3DOF_G_BASIC(struct SV_3DOF_G_BASIC *pthisSV, struct AccelSensor *pthisAccel, float flpftimesecs);
95 void fInit_3DOF_B_BASIC(struct SV_3DOF_B_BASIC *pthisSV, struct MagSensor *pthisMag, float flpftimesecs);
96 void fInit_3DOF_Y_BASIC(struct SV_3DOF_Y_BASIC *pthisSV);
97 void fInit_6DOF_GB_BASIC(struct SV_6DOF_GB_BASIC *pthisSV, struct AccelSensor *pthisAccel, struct MagSensor *pthisMag, float flpftimesecs);
98 void fInit_6DOF_GY_KALMAN(struct SV_6DOF_GY_KALMAN *pthisSV, struct AccelSensor *pthisAccel, struct GyroSensor *pthisGyro);
99 void fInit_9DOF_GBY_KALMAN(struct SV_9DOF_GBY_KALMAN *pthisSV, struct AccelSensor *pthisAccel, struct MagSensor *pthisMag,
100  struct GyroSensor *pthisGyro, struct MagCalibration *pthisMagCal);
101 void fRun_1DOF_P_BASIC(struct SV_1DOF_P_BASIC *pthisSV, struct PressureSensor *pthisPressure);
102 void fRun_3DOF_G_BASIC(struct SV_3DOF_G_BASIC *pthisSV, struct AccelSensor *pthisAccel);
103 void fRun_3DOF_B_BASIC(struct SV_3DOF_B_BASIC *pthisSV, struct MagSensor *pthisMag);
104 void fRun_3DOF_Y_BASIC(struct SV_3DOF_Y_BASIC *pthisSV, struct GyroSensor *pthisGyro);
105 void fRun_6DOF_GB_BASIC(struct SV_6DOF_GB_BASIC *pthisSV, struct MagSensor *pthisMag, struct AccelSensor *pthisAccel);
106 void fRun_6DOF_GY_KALMAN(struct SV_6DOF_GY_KALMAN *pthisSV, struct AccelSensor *pthisAccel, struct GyroSensor *pthisGyro);
107 void fRun_9DOF_GBY_KALMAN(struct SV_9DOF_GBY_KALMAN *pthisSV, struct AccelSensor *pthisAccel, struct MagSensor *pthisMag, struct GyroSensor *pthisGyro, struct MagCalibration *pthisMagCal);
108 ///@}
109 
110 #endif // #ifndef FUSION_H
SV_3DOF_Y_BASIC structure is the 3DOF basic gyroscope state vector structure.
void fRun_9DOF_GBY_KALMAN(struct SV_9DOF_GBY_KALMAN *pthisSV, struct AccelSensor *pthisAccel, struct MagSensor *pthisMag, struct GyroSensor *pthisGyro, struct MagCalibration *pthisMagCal)
void fRun_6DOF_GB_BASIC(struct SV_6DOF_GB_BASIC *pthisSV, struct MagSensor *pthisMag, struct AccelSensor *pthisAccel)
Definition: fusion.c:610
void fRun_1DOF_P_BASIC(struct SV_1DOF_P_BASIC *pthisSV, struct PressureSensor *pthisPressure)
Definition: fusion.c:447
void fInit_9DOF_GBY_KALMAN(struct SV_9DOF_GBY_KALMAN *pthisSV, struct AccelSensor *pthisAccel, struct MagSensor *pthisMag, struct GyroSensor *pthisGyro, struct MagCalibration *pthisMagCal)
Definition: fusion.c:378
void fInit_3DOF_G_BASIC(struct SV_3DOF_G_BASIC *pthisSV, struct AccelSensor *pthisAccel, float flpftimesecs)
Definition: fusion.c:197
The top level fusion structure.
This is the 3DOF basic accelerometer state vector structure.
The AccelSensor structure stores raw and processed measurements for a 3-axis accelerometer.
Magnetic Calibration Structure.
Definition: magnetic.h:72
void fRun_6DOF_GY_KALMAN(struct SV_6DOF_GY_KALMAN *pthisSV, struct AccelSensor *pthisAccel, struct GyroSensor *pthisGyro)
Definition: fusion.c:663
The SV_1DOF_P_BASIC structure contains state information for a pressure sensor/altimeter.
This is the 3DOF basic magnetometer state vector structure/.
The PressureSensor structure stores raw and processed measurements for an altimeter.
void fFuseSensors(struct SV_1DOF_P_BASIC *pthisSV_1DOF_P_BASIC, struct SV_3DOF_G_BASIC *pthisSV_3DOF_G_BASIC, struct SV_3DOF_B_BASIC *pthisSV_3DOF_B_BASIC, struct SV_3DOF_Y_BASIC *pthisSV_3DOF_Y_BASIC, struct SV_6DOF_GB_BASIC *pthisSV_6DOF_GB_BASIC, struct SV_6DOF_GY_KALMAN *pthisSV_6DOF_GY_KALMAN, struct SV_9DOF_GBY_KALMAN *pthisSV_9DOF_GBY_KALMAN, struct AccelSensor *pthisAccel, struct MagSensor *pthisMag, struct GyroSensor *pthisGyro, struct PressureSensor *pthisPressure, struct MagCalibration *pthisMagCal)
Definition: fusion.c:86
void fInit_3DOF_Y_BASIC(struct SV_3DOF_Y_BASIC *pthisSV)
Definition: fusion.c:259
SV_6DOF_GB_BASIC is the 6DOF basic accelerometer and magnetometer state vector structure.
void fRun_3DOF_B_BASIC(struct SV_3DOF_B_BASIC *pthisSV, struct MagSensor *pthisMag)
Definition: fusion.c:517
void fInit_6DOF_GB_BASIC(struct SV_6DOF_GB_BASIC *pthisSV, struct AccelSensor *pthisAccel, struct MagSensor *pthisMag, float flpftimesecs)
Definition: fusion.c:277
The sensor_fusion.h file implements the top level programming interface.
void fInit_1DOF_P_BASIC(struct SV_1DOF_P_BASIC *pthisSV, struct PressureSensor *pthisPressure, float flpftimesecs)
Definition: fusion.c:172
void fInit_6DOF_GY_KALMAN(struct SV_6DOF_GY_KALMAN *pthisSV, struct AccelSensor *pthisAccel, struct GyroSensor *pthisGyro)
Definition: fusion.c:313
void fInitializeFusion(SensorFusionGlobals *sfg)
Definition: fusion.c:51
void fRun_3DOF_Y_BASIC(struct SV_3DOF_Y_BASIC *pthisSV, struct GyroSensor *pthisGyro)
Definition: fusion.c:562
The MagSensor structure stores raw and processed measurements for a 3-axis magnetic sensor...
SensorFusionGlobals sfg
This is the primary sensor fusion data structure.
void fInit_3DOF_B_BASIC(struct SV_3DOF_B_BASIC *pthisSV, struct MagSensor *pthisMag, float flpftimesecs)
Definition: fusion.c:228
The GyroSensor structure stores raw and processed measurements for a 3-axis gyroscope.
void fRun_3DOF_G_BASIC(struct SV_3DOF_G_BASIC *pthisSV, struct AccelSensor *pthisAccel)
Definition: fusion.c:467
SV_6DOF_GY_KALMAN is the 6DOF Kalman filter accelerometer and gyroscope state vector structure...
SV_9DOF_GBY_KALMAN is the 9DOF Kalman filter accelerometer, magnetometer and gyroscope state vector s...